#include <algorithm>
#include <cstdio>

typedef long long ll;
int n;
ll l1, r1, l2, r2, l3, r3, l4, r4;

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("mulsum.in", "r", stdin);
  freopen("mulsum.out", "w", stdout);
#endif
#endif

  scanf("%lld%lld%lld%lld%lld%lld%lld%lld", &l1, &r1, &l2, &r2, &l3, &r3, &l4, &r4);
  ll ans = 0;
  for (ll i = l1; i <= r1; ++i) {
    for (ll j = std::max(l2, i - r3); j <= std::min(r2, i - l3); ++j) {
      if ((i ^ j) <= r4 && (i ^ j) >= l4) ans += i * j;
    }
    if (l3 == 0) ans -= i * i;
    for (ll j = std::max(l2, i + l3); j <= std::min(r2, i + r3); ++j) {
      if ((i ^ j) <= r4 && (i ^ j) >= l4) ans += i * j;
    }
  }
  printf("%lld", ans);
  return 0;
}